package net.hn.hnms.biz.emgcy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.hn.hnms.biz.emgcy.domain.EmgcyPlanPo;
import net.hn.hnms.biz.emgcy.domain.dto.EmgcyPlanDto;
import net.hn.hnms.biz.emgcy.domain.vo.EmgcyPlanVo;
import net.hn.hnms.biz.emgcy.mapper.EmgcyPlanMapper;
import net.hn.hnms.biz.emgcy.service.EmgcyPlanService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: baijiajun
 * @Date: 2022/9/13
 */
@Service
public class EmgcyPlanServiceImpl extends ServiceImpl<EmgcyPlanMapper, EmgcyPlanPo> implements EmgcyPlanService {
    @Autowired
    private EmgcyPlanMapper emgcyPlanMapper;

    @Override
    public ResponsePage<EmgcyPlanVo> pageList(PageQuery pageQuery, EmgcyPlanDto emgcyPlanDto) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? (pageQuery.getPageNum() - 1) * pageQuery.getPageSize():0);
        List<EmgcyPlanVo> list =  emgcyPlanMapper.pageList(pageQuery.getPageSize(), pageQuery.getPageNum(), emgcyPlanDto);
        if(list.isEmpty()){
            return new ResponsePage<>(new ArrayList(),0);
        }
        return new ResponsePage<>(list,list.get(0).getTotal());
    }

    @Override
    public Boolean add(EmgcyPlanPo emgcyPlanPo) {
        int insert = emgcyPlanMapper.insert(emgcyPlanPo);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean update(EmgcyPlanPo emgcyPlanPo) {
        int update = emgcyPlanMapper.updateById(emgcyPlanPo);
        if(update>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean delete(Long id) {
        int delete = emgcyPlanMapper.deleteById(id);
        if(delete>0){
            return true;
        }
        return false;
    }

    @Override
    public EmgcyPlanPo getOne(String eventType) {
        return emgcyPlanMapper.getOne(eventType);
    }
}
